package com.android.thought.badboys;

import java.util.Set;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

public class SharedPreferenceUtil {

	static private final String PREF_NAME = "com.android.thought.badboys";

	public final static String PREF_INTRO_USER_AUTO_MESSAGE = "PREF_AUTO_MESSAGE";
	public final static String PREF_INTRO_MESSAGE_SET_INFO = "PREF_MESSAGE_SET";
	public final static String PREF_INTRO_MESSAGE_HISTORY = "PREF_MESSAGE_HISTORY";

	
	static Context mContext;

	public static void getInstance(Context c) { 
		mContext = c;
	}

	static  public void put(String key, String value) {
		SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();

		editor.putString(key, value);
		editor.commit();
	}

	static  public void put(String key, boolean value) {
		SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();
		
		editor.putBoolean(key, value);
		
		editor.commit();
	}

	static  public void put(String key, int value) {
		SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();

		editor.putInt(key, value);
		editor.commit();
	}
	
	static  public void put(String key, Set<String> value) {
		SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);
		SharedPreferences.Editor editor = pref.edit();

		editor.putStringSet(key, value);
		editor.commit();
	}

	static  public String getValue(String key, String dftValue) {
		SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);

		try {
			return pref.getString(key, dftValue);
		} catch (Exception e) {
			return dftValue;
		}

	}

	static  public int getValue(String key, int dftValue) {
		SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);
		try {
			return pref.getInt(key, dftValue);
		} catch (Exception e) {
			return dftValue;
		}

	}

	static  public boolean getValue(String key, boolean dftValue) {
		SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);

		try {
			return pref.getBoolean(key, dftValue);
		} catch (Exception e) {
			return dftValue;
		}
	}
	
	static  public Set<String> getValue(String key, Set<String> dftValue) {
		SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);

		try {
			return pref.getStringSet(key, dftValue);
		} catch (Exception e) {
			return dftValue;
		}

	}
	
}
/*
 * 
 * 
 * RbPreference pref = new RbPreference(this);
 * 
 * // set pref.put(RbPreference.PREF_USER_AGREEMENT, true);
 * 
 * // get pref.getValue(RbPreference.PREF_USER_AGREEMENT, false);
 */
